<template>
  <component
    :is="comName"
    v-bind="$attrs"
    :id="id"
    :relative-data="config"
    :relative-type="relativeType"
    :default-value="defaultValue"
    :default-rate="defaultRate"
    @change="handleProductChange" />
</template>

<script>
/**
 * Create by yxk at 2020/6/11
 */
import PurchaseChoose from './PurchaseChoose' // 采购选择产品
import RetreatChoose from './RetreatChoose' // 采购退货选择产品
import SaleProductChoose from './SaleProductChoose' // 销售选择产品
import SaleReturnChoose from './SaleReturnChoose' // 销售退货选择产品
import ReceiptChoose from './ReceiptChoose' // 入库选择产品
import OutboundChoose from './OutboundChoose' // 出库选择产品
import AllocationChoose from './AllocationChoose' // 调拨选择产品
import InventoryChoose from './InventoryChoose' // 盘点选择产品

export default {
  name: 'ProductAllCell',
  components: {
    PurchaseChoose,
    RetreatChoose,
    SaleProductChoose,
    SaleReturnChoose,
    ReceiptChoose,
    OutboundChoose,
    AllocationChoose,
    InventoryChoose
  },
  props: {
    config: {
      type: Object,
      required: true
    },
    type: {
      type: String,
      required: true
    },
    defaultValue: {
      type: Array,
      default: () => []
    },
    defaultRate: {
      type: [String, Number],
      default: 0
    },
    relativeType: {
      type: String,
      default: ''
    }
  },
  data() {
    return {}
  },
  computed: {
    comName() {
      return {
        jxc_purchase: 'PurchaseChoose',
        jxc_retreat: 'RetreatChoose',
        jxc_sale: 'SaleProductChoose',
        jxc_salereturn: 'SaleReturnChoose',
        jxc_receipt: 'ReceiptChoose',
        jxc_outbound: 'OutboundChoose',
        jxc_allocation: 'AllocationChoose',
        jxc_inventory: 'InventoryChoose'
      }[this.type]
    },
    id() {
      const key = {
        jxc_purchase: 'supplierId',
        jxc_retreat: 'purchaseId',
        jxc_receipt: 'orderId',
        jxc_salereturn: 'saleId',
        jxc_outbound: 'orderId',
        jxc_allocation: 'originalWarehouseId'
      }[this.type]
      return this.config[key] || null
    }
  },
  methods: {
    handleProductChange(...obj) {
      this.$emit('change', ...obj)
    }
  }
}
</script>

<style scoped>

</style>
